<html>
<head></head>
<body>
<script type="text/javascript" src="jquery.js"></script>

<script>
OptionsBackend = {
  defaultOptions: {
    hint_icon: "small",
    hint_fadeout_time: 3 * 1000,
    min_img_width: 100,
    min_img_height: 100
  },
  cachedOptions: null,
  save: function(optionsMap) {
    localStorage['options'] = JSON.stringify(optionsMap);
    this.cachedOptions = this.load();
  },
  load: function(forceDefault) {
    var map = $.extend(true, {}, this.defaultOptions);
    if(forceDefault) {
      return map;
    }
    try {
      var parsedMap = JSON.parse(localStorage['options']);
      if(parsedMap)
        $.extend(true, map, parsedMap);
    } catch(e) { /* ignored */ }
    return map;
  },
  get: function(option) {
    if(this.cachedOptions == null) {
      this.cachedOptions = this.load();
    }
    return this.cachedOptions[option];
  }
};

chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
    if (request.cmd == "getOptions")
      sendResponse(JSON.stringify(OptionsBackend.load()));
    else
      sendResponse({}); 
  });

</script>
</body>
</html>
